const webpack = require('webpack');
const ExtractTextPlugin = require('extract-text-webpack-plugin');

const base = require('./webpack.base');

const env = process.env.NODE_ENV || 'development';

const config = Object.assign({}, base, {
    plugins: [
        new webpack.DefinePlugin({
            'process.env.NODE_ENV': JSON.stringify(env),
            'isBrowser': true
        })
    ]
});

config.vue = {
    loaders: {
        css: ExtractTextPlugin.extract({
            loader: 'css-loader',
            fallbackLoader: 'vue-style-loader'
        }),
        sass: ExtractTextPlugin.extract('vue-style-loader', 'css!sass?indentedSyntax'),
        scss: ExtractTextPlugin.extract('vue-style-loader', 'css!sass')
    }
};
config.plugins.push(new ExtractTextPlugin('style.css'));

if (env === 'production') {
    config.plugins.push(
        new webpack.LoaderOptionsPlugin({
            minimize: true
        }),
        new webpack.optimize.UglifyJsPlugin({
            compress: {
                warnings: false
            }
        })
    );
}

module.exports = config;